<?php


namespace app\merchant\system\service;


use app\common\model\SysMerchantAdmin;
use support\exception\BadException;
use support\utils\TenantUtil;
use support\utils\UserUtil;
use Webman\Http\Request;

class MerAuthService
{
    static function checkAndSetRequest(Request $request, $token)
    {
        $user = SysMerchantAdmin::where(['token' => $token])->field(['id', 'tenant_id'])->find();
        if (!$user) {
            throw new BadException("登录异常", 401);
        }
        UserUtil::setUid(intval($user['id']));
        TenantUtil::setTenantId($user['tenant_id']); //设置商户标识
    }
}